import React from 'react'
import actionCreators from '../store/actionCreators/counter1'
import {connect} from '../react-redux'

class Counter1 extends React.Component {
    render() {
        const {props} = this
        return (<div>
            <p>{props.number}</p>
            <button onClick={ props.add1}>+</button>
            <button onClick={ props.minus1}>-</button>
            <button onClick={ props.thunkAction}>thunk</button>
            <button onClick={ props.promiseAction}>promise</button>
        </div>)
    }
}


/**
 *
 * connect用来连接 组件和仓库
 * 将仓库的状态输入到组件中
 * 将dispatch方法输入到组建中 
 *
 */
const mapStateToProps = state=> state.counter1
const mapDispatchToProps = actionCreators
// const mapDispatchToProps  = (dispatch)=>({
//     add1(){
//        dispatch({type: 'ADD1'}) 
//     },
//     minus1(){
//         dispatch({type: 'MINUS1'}) 
//      },
// })

 

export default connect(mapStateToProps,mapDispatchToProps)(Counter1)